package com.dean.utils;

import com.dean.entity.DeanDbConnInfo;
import com.dean.entity.ExcelQueryResult;
import com.dean.entity.SysDbConnInfo;
import com.dean.service.DeanExecutorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

/**
 * 不带返回值的多线程调用
 * @author Administrator
 *
 */
public class GenExcelUtils implements Runnable {
	
	private static final Logger logger = LoggerFactory.getLogger(GenExcelUtils.class);
	
	private String fileName;
	
	private String exeSql;

	private SysDbConnInfo connectInfo;

	public GenExcelUtils(SysDbConnInfo connectInfo, String exeSql, String fileName){
		this.fileName = fileName;
		this.exeSql = exeSql;
		this.connectInfo = connectInfo;
	}

	public SysDbConnInfo getConnectInfo() {
		return connectInfo;
	}

	public void setConnectInfo(SysDbConnInfo connectInfo) {
		this.connectInfo = connectInfo;
	}

	public  String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getExeSql() {
		return exeSql;
	}

	public void setExeSql(String exeSql) {
		this.exeSql = exeSql;
	}

	@Override
	public void run() {
		logger.info("当前线程:{},导出文件名称:{},执行sql:{},当前时间:{}",Thread.currentThread().getName(),fileName,exeSql,LocalDateTime.now());
		ExcelQueryResult result = DeanJdbcUtils.query(connectInfo,exeSql);
		DeanEasyExcelUtils.writeExcel(fileName,result);
		DeanExecutorService.consumer("excel export task sql:"+exeSql);
	}

}
